package com.ymttest.database.sqlwapper.fqlorder;

import java.util.Date;
import java.util.List;

import com.ymt.database.SqlManager;
import com.ymttest.database.model.fqlorder.FqlSyncOrderDetail;

public class FqlSyncOrderDetailWrapper {
	
	SqlManager manager;

	public FqlSyncOrderDetailWrapper() {
		manager = new SqlManager("fqlordersync");
	}

	@SuppressWarnings("unchecked")
	public FqlSyncOrderDetail selectByPrimaryKey(Long id) {

		FqlSyncOrderDetail fqlSyncOrderDetail = new FqlSyncOrderDetail();
		List<FqlSyncOrderDetail> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.fqlorder.FqlSyncOrderDetailMapper.selectByPrimaryKey",
						id);
		manager.commit();

		if (result.size() > 0) {
			fqlSyncOrderDetail = result.get(0);
		}

		return fqlSyncOrderDetail;
	}
	
	@SuppressWarnings("unchecked")
	public FqlSyncOrderDetail selectByFqlOrderId(String fqlOrderId) {

		FqlSyncOrderDetail fqlSyncOrderDetail = new FqlSyncOrderDetail();
		List<FqlSyncOrderDetail> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.fqlorder.FqlSyncOrderDetailMapper.selectByFqlOrderId",
						fqlOrderId);
		manager.commit();

		if (result.size() > 0) {
			fqlSyncOrderDetail = result.get(0);
		}

		return fqlSyncOrderDetail;
	}
	
	/**
	 * 
	 * @param fql_order_id
	 * @param fql_shop_id (fql_shop中的数据)
	 * @return
	 */
	public int insert(String fql_order_id, long fql_shop_id) {
		
		return this.insert(fql_order_id, fql_shop_id, null);
	}
	
	/**
	 * 
	 * @param fql_order_id
	 * @param fql_shop_id (fql_shop中的数据)
	 * @return
	 */
	public int insert(String fql_order_id, long fql_shop_id, Long orderId) {
		
		FqlSyncOrderDetail fqlSyncOrderDetail = new FqlSyncOrderDetail();
		
		fqlSyncOrderDetail.setOrder_id(orderId);
		fqlSyncOrderDetail.setFql_order_id(fql_order_id);
		fqlSyncOrderDetail.setFql_order_status((byte)12);
		fqlSyncOrderDetail.setFql_shop_id(fql_shop_id);
		fqlSyncOrderDetail.setSync_status((byte)0);
		fqlSyncOrderDetail.setSync_confirm_receive_status((byte)0);
		fqlSyncOrderDetail.setAdd_time(new Date());
		fqlSyncOrderDetail.setUpdate_time(new Date());
		
		int result = manager
				.insert("com.ymttest.database.mapping.fqlorder.FqlSyncOrderDetailMapper.insert",
						fqlSyncOrderDetail);
		
		manager.commit();
		
		return result;
	}
	
	public static void main(String[] args) {
		
		FqlSyncOrderDetailWrapper wrapper = new FqlSyncOrderDetailWrapper();
		
		wrapper.insert("sfsdgsdf", 2);
		
		System.out.println(wrapper.selectByPrimaryKey(1L).getLast_error_code());
	}
}
